:root {
    --primary-color: #3498db;
    --secondary-color: #2ecc71;
    --background-color: #f5f7f9;
    --card-bg: #ffffff;
    --text-color: #333333;
    --border-color: #e0e0e0;
    --request-color: #e3f2fd;
    --response-color: #f1f8e9;
    --think-color: #fff3e0;
    --search-color: #e8f5e9;
    --reasoner-color: #bb86fc;
    --chat-color: #03dac6;
    --sidebar-width: 320px;
    --resize-handle-width: 5px;
    --conversation-list-header-bg: #f0f0f0;
}

/* 深色模式变量 */
[data-theme="dark"] {
    --primary-color: #5dade2;
    --secondary-color: #58d68d;
    --background-color: #1a1a1a;
    --card-bg: #2d2d2d;
    --text-color: #e0e0e0;
    --border-color: #444;
    --request-color: #2c3e50;
    --response-color: #2e4053;
    --think-color: #34495e;
    --search-color: #2c3e50;
    --search-filters-bg: #333;
    --conversation-list-header-bg: #333;
    --link-color: #5dade2;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--background-color);
    color: var(--text-color);
    line-height: 1.6;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    transition: background-color 0.3s, color 0.3s;
}

header {
    padding: 12px 20px;
    background: var(--card-bg);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    z-index: 10;
    flex-shrink: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
}

.header-main {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    min-width: 0;
    flex: 1;
}

.header-controls {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-end;
}

/* 宽屏布局 - 单行横向排列 */
@media (min-width: 1025px) {
    .header-controls {
        flex-direction: row;
        flex-wrap: nowrap;
    }
    .header-controls button {
        width: auto;
        min-width: 100px;
    }
}

/* 中等屏幕布局 - 两行排列 */
@media (min-width: 601px) and (max-width: 1024px) {
    .header-controls {
        width: 100%;
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: flex-start;
    }
    .header-controls button {
        flex: 0 0 calc(25% - 8px);
        min-width: 120px;
    }
}

/* 窄屏布局 - 三列排列 */
@media (max-width: 600px) {
    .header-controls {
        width: 100%;
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: flex-start; /* 修改为左对齐，尽量一行，空间不足自动换行 */
        gap: 8px;
    }
    .header-controls button {
        flex: 0 0 auto;
        width: 40px;
        min-width: 40px;
        max-width: 40px;
        height: 40px;
        min-height: 40px;
        max-height: 40px;
        font-size: 1.2rem;
        margin-bottom: 6px;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 0;
    }
    /* 隐藏按钮文字，仅显示图标 */
    .header-controls button > span {
        display: none;
    }
    .header-controls button i {
        margin-right: 0 !important;
    }
}

/* 固定关闭按钮宽度 */
.close-modal {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-color);
    width: 40px;
    min-width: 40px;
    max-width: 40px;
    text-align: center;
    padding: 0;
}

.loading {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 20px;
    border-radius: 8px;
    z-index: 1000;
}

.loading-spinner {
    border: 4px solid #f3f3f3;
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    width: 30px;
    height: 30px;
    animation: spin 1s linear infinite;
    margin: 0 auto 10px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

h1 {
    color: var(--primary-color);
    margin-bottom: 5px;
    font-size: 1.5rem;
}

.main-container {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--card-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: width 0.3s ease;
}

.sidebar.collapsed {
    width: 0;
    overflow: hidden;
    border-right: none;
}

.resize-handle {
    width: var(--resize-handle-width);
    background-color: #ddd;
    cursor: col-resize;
    flex-shrink: 0;
    position: relative;
    z-index: 10;
    transition: opacity 0.3s ease;
}

.resize-handle.hidden {
    opacity: 0;
    pointer-events: none;
}

.resize-handle:hover {
    background-color: var(--primary-color);
}

.upload-section {
    padding: 15px;
    border-bottom: 1px solid var(--border-color);
    transition: max-height 0.3s, opacity 0.3s;
    max-height: 800px;
    opacity: 1;
    overflow: hidden;
    position: relative;
}

.upload-modal {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 600px;
    background: var(--card-bg);
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    z-index: 1001;
    padding: 20px;
    max-height: 80vh;
    overflow-y: auto;
}

.upload-modal.active {
    display: block;
}

.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
}

.modal-overlay.active {
    display: block;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-color);
}

.close-modal {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-color);
    width: 40px;
    min-width: 40px;
    max-width: 40px;
    text-align: center;
    padding: 0;
}

.search-filters {
    padding: 15px;
    border-bottom: 1px solid var(--border-color);
    background: var(--search-filters-bg, #f9f9f9);
}

.search-box {
    position: relative;
    margin-bottom: 10px;
}

.search-box input {
    width: 100%;
    padding: 8px 12px 8px 35px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 0.9rem;
    background: var(--card-bg);
    color: var(--text-color);
}

.search-box i {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: #999;
}

.search-stats {
    font-size: 0.85rem;
    color: var(--text-color);
    margin-top: 10px;
    opacity: 0.8;
}

.date-filter {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

.date-filter input {
    flex: 1;
    padding: 6px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 0.85rem;
    background: var(--card-bg);
    color: var(--text-color);
}

.sort-options {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

.sort-options select {
    flex: 1;
    padding: 6px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--card-bg);
    color: var(--text-color);
}

.conversation-list {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.conversation-list-header {
    padding: 12px 15px;
    background: var(--conversation-list-header-bg);
    font-weight: bold;
    font-size: 0.9rem;
    position: sticky;
    top: 0;
    z-index: 5;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.conversations-container {
    flex: 1;
    overflow-y: auto;
}

.content-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: width 0.3s ease;
}

.content-area.collapsed {
    width: 0;
    overflow: hidden;
}

.conversation-detail {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: var(--card-bg);
}

.file-upload {
    border: 2px dashed var(--border-color);
    border-radius: 8px;
    padding: 15px;
    text-align: center;
    margin-bottom: 15px;
    cursor: pointer;
    transition: all 0.3s;
}

.file-upload:hover {
    border-color: var(--primary-color);
    background-color: rgba(52, 152, 219, 0.05);
}

.json-input {
    width: 100%;
    height: 100px;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    font-family: monospace;
    resize: vertical;
    font-size: 0.9rem;
    background: var(--card-bg);
    color: var(--text-color);
}

button {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 8px 12px;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
    transition: background-color 0.3s;
    margin-top: 0;
    width: 100%;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
}

button:hover {
    background-color: #2980b9;
}

.conversation-item {
    padding: 12px 15px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background-color 0.2s;
}

.conversation-item:hover {
    background-color: rgba(52, 152, 219, 0.1);
}

.conversation-item.active {
    background-color: rgba(52, 152, 219, 0.2);
    border-left: 4px solid var(--primary-color);
}

.conversation-title {
    font-weight: bold;
    margin-bottom: 4px;
    color: var(--primary-color);
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-time {
    font-size: 0.8rem;
    color: #777;
}

.message {
    margin-bottom: 20px;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 6px rgba(0,0,0,0.08);
    page-break-inside: avoid;
}

.message-header {
    display: flex;
    justify-content: space-between;
    padding: 10px 15px;
    font-size: 0.85rem;
    font-weight: bold;
}

.message-content {
    padding: 15px;
}

.request .message-header {
    background-color: rgba(52, 152, 219, 0.15);
    color: #1967a2;
}

.request .message-content {
    background-color: var(--request-color);
}

.response .message-header {
    background-color: rgba(46, 204, 113, 0.15);
    color: #1e7e34;
}

.response .message-content {
    background-color: var(--response-color);
}

.think .message-header {
    background-color: rgba(255, 179, 0, 0.15);
    color: #b36b00;
}

.think .message-content {
    background-color: var(--think-color);
}

.search .message-header {
    background-color: rgba(76, 175, 80, 0.15);
    color: #2e7d32;
}

.search .message-content {
    background-color: var(--search-color);
}

.model-tag {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.75rem;
    margin-left: 8px;
}

.reasoner {
    background-color: var(--reasoner-color);
    color: white;
}

.chat {
    background-color: var(--chat-color);
    color: black;
}

.code-block {
    position: relative;
    margin: 10px 0;
    background: #2d2d2d;
    border-radius: 5px;
}

.code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #2d2d2d;
    color: #f8f8f2;
    padding: 5px 10px;
    border-top-left-radius: 5px;
    border-top-right-radius: 5px;
    font-size: 0.8rem;
}

.code-actions {
    display: flex;
    gap: 5px;
}

.code-btn {
    background: rgba(255, 255, 255, 0.7);
    border: none;
    border-radius: 3px;
    padding: 3px 8px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: background 0.2s;
    color: #333;
}

.code-btn:hover {
    background: rgba(255, 255, 255, 0.9);
}

pre {
    border-radius: 0 0 5px 5px;
    padding: 12px;
    overflow-x: auto;
    background: #2d2d2d;
    color: #f8f8f2;
    font-size: 0.85rem;
    border: 1px solid #555;
    margin: 0;
}

[data-theme="dark"] pre {
    border: 1px solid #666;
}

.search-result {
    margin-bottom: 12px;
    padding: 12px;
    border-radius: 5px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
}

a {
    color: var(--primary-color);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

[data-theme="dark"] a {
    color: var(--link-color, #5dade2);
}

.search-title {
    font-weight: bold;
    margin-bottom: 5px;
    font-size: 0.9rem;
}

.search-snippet {
    font-size: 0.85rem;
    color: var(--text-color);
    opacity: 0.8;
}

.timestamp {
    font-size: 0.8rem;
    color: #777;
}

.conversation-header {
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
}

.fragment {
    margin-bottom: 15px;
    padding: 12px;
    border-radius: 6px;
    background: var(--card-bg);
    border-left: 4px solid transparent;
}

.fragment:last-child {
    margin-bottom: 0;
}

.fragment.request {
    border-left-color: #3498db;
}

.fragment.response {
    border-left-color: #2ecc71;
}

.fragment.think {
    border-left-color: #ffb300;
}

.fragment.search {
    border-left-color: #4caf50;
}

.fragment-header {
    font-weight: bold;
    margin-bottom: 8px;
    font-size: 0.85rem;
    color: #555;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.fragment-divider {
    height: 1px;
    background: var(--border-color);
    margin: 10px 0;
}

.branch-navigation {
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 15px 0;
    padding: 10px;
    background: var(--card-bg);
    border-radius: 6px;
    border: 1px solid var(--border-color);
    width: 200px;
    min-width: 50px;
    max-width: 100%;
    margin-left: auto;
    margin-right: auto;
    box-sizing: border-box;
}

.branch-nav-btn {
    padding: 0;
    width: 30px;
    height: 30px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    margin: 0 2px;
    min-width: 30px;
    min-height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
}

.branch-nav-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.branch-input {
    width: 40px;
    height: 30px;
    text-align: center;
    padding: 0;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    margin: 0 5px;
    background: var(--card-bg);
    color: var(--text-color);
    font-size: 15px;
    box-sizing: border-box;
}

/* Markdown 表格样式 */
table {
    border-collapse: collapse;
    width: 100%;
    margin: 10px 0;
    border: 1px solid var(--border-color);
}

th, td {
    border: 1px solid var(--border-color);
    padding: 8px;
    text-align: left;
}

th {
    background-color: rgba(0, 0, 0, 0.05);
    font-weight: bold;
}

/* 有序列表缩进 */
ol {
    padding-left: 2em;
}

li {
    margin: 5px 0;
}

.highlight {
    background-color: yellow;
    color: black;
    padding: 2px 0;
}

/* 响应式设计 */
@media (orientation: portrait) {
    .main-container {
        flex-direction: column;
    }
    .sidebar {
        width: 100% !important;
        border-right: none;
        max-height: 50vh;
        overflow-y: auto;
        transition: none;
    }
    .resize-handle {
        display: none;
    }
    .conversation-detail {
        padding: 15px;
    }
    .conversation-list {
        display: none;
    }
    .conversation-list.expanded {
        display: flex;
        flex-direction: column;
        height: auto;
        max-height: 40vh;
        min-height: 100px;
        border-bottom: 1px solid var(--border-color);
        background: var(--card-bg);
        z-index: 2;
    }
    /* 保证搜索栏始终显示 */
    .search-filters {
        display: block !important;
        position: relative;
        z-index: 21;
    }
    /* 新增：正文折叠时对话列表扩展覆盖正文区域，但不影响搜索栏 */
    .conversation-list.expanded.cover-content {
        position: absolute;
        left: 0;
        right: 0;
        top: 0;
        bottom: 0;
        height: 100%;
        max-height: none;
        min-height: 0;
        background: var(--card-bg);
        z-index: 20;
        box-shadow: 0 0 10px rgba(0,0,0,0.08);
        /* 保证搜索栏在上方，列表内容下移 */
        padding-top: 180px;
    }
    /* 纵向布局下显示正文切换按钮 */
    .toggle-content-btn {
        display: block !important;
    }

    /* 确保对话列表容器可以滚动 */
    .conversations-container {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch; /* 改善移动端滚动体验 */
    }
    
    /* 当对话列表覆盖整个内容区域时，确保其可以滚动 */
    .conversation-list.expanded.cover-content {
        height: 100%;
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }
    
    .conversation-list.expanded.cover-content .conversations-container {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* 确保搜索栏不随内容滚动 */
    .search-filters {
        flex-shrink: 0;
    }
}
/* 横向布局下隐藏正文切换按钮 */
@media (orientation: landscape) {
    .toggle-content-btn {
        display: none !important;
    }
}

@media print {
    header, .sidebar, .resize-handle, .header-controls,
    .code-actions, .branch-navigation {
        display: none !important;
    }
    
    .main-container {
        display: block;
        height: auto;
        overflow: visible;
    }
    
    .content-area {
        display: block;
        overflow: visible;
        height: auto;
    }
    
    .conversation-detail {
        padding: 0;
        overflow: visible;
        height: auto;
    }
    
    .message {
        box-shadow: none;
        border: 1px solid #ddd;
        page-break-inside: avoid;
    }
    
    body, html {
        height: auto;
        overflow: visible;
        color: #000 !important;
        background: white !important;
    }
    
    .message-content, .fragment {
        background: white !important;
        color: #000 !important;
    }
    
    a {
        color: #0000ee !important;
    }

    pre {
        background: #f5f5f5 !important;
        color: #333 !important;
        border: 1px solid #ddd !important;
        page-break-inside: avoid;
    }

    .code-header {
        background: #eee !important;
        color: #333 !important;
    }
}